package com.acyouzi.leetcode.tree;

/**
 * 17/9/12 12:33
 *
 * @author sunxu
 */
public class SubtreeAnotherTree {
  // https://leetcode.com/problems/subtree-of-another-tree/solution/
  public boolean isSubtree(TreeNode s, TreeNode t) {
    String tree1 = preorder(s, true);
    String tree2 = preorder(t, true);
    return tree1.indexOf(tree2) >= 0;
  }
  public String preorder(TreeNode t, boolean left) {
    if (t == null) {
      if (left)
        return "lnull";
      else
        return "rnull";
    }
    return "#"+t.val + " " +preorder(t.left, true)+" " +preorder(t.right, false);
  }
}
